//
//  HRenameWC.m
//  HMusicPlayer
//
//  Created by hament deng on 14/10/24.
//  Copyright (c) 2014年 HJ. All rights reserved.
//

#import "HRenameWC.h"
#import "HCoreConfig.h"
#import "HMainWC.h"
#import "HJAudioPlayer.h"
#import "HSongItem.h"

@interface HRenameWC ()

@end

@implementation HRenameWC

- (void)windowDidLoad {
    [super windowDidLoad];
    
    // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
    
    
    //翻译
    [self.window setTitle:NSLocalizedString(@"rename", nil)];
    [self.okBtn setTitle:NSLocalizedString(@"Save", nil)];
    [[self.nameTf cell] setPlaceholderString:NSLocalizedString(@"inputNameDes", nil)];
    
    
}

- (IBAction)save:(NSButton *)sender {
    
    NSCharacterSet *  whitespaceSet= [NSCharacterSet whitespaceAndNewlineCharacterSet];
    NSString * nTx=[self.nameTf.stringValue stringByTrimmingCharactersInSet:whitespaceSet];
    //检查总量是否为空
    if ([CHECKSTR(nTx) isEqualToString:@""] ) {
        [[self.nameTf cell] setPlaceholderString:NSLocalizedString(@"inputNameDes", nil)];
        
        [[HMainWC shareWc].window makeFirstResponder:self.nameTf];//select ring
        
        self.nameTf.stringValue=@"";
        return;
    }

    
    HSongItem * cusongItem=[HJAudioPlayer sharePlayer].currentPlaySongItem;
    if (cusongItem ) {
        
        if ([cusongItem.syncid isEqualToString:self.currentSongSyncid]) {
            
            [HCoreConfig alertWithTitle:NSLocalizedString(@"CurrentSongEditErrorDES", nil) window:self.window];
            return;
        }
 
    }
    
    
    //保存
    if (self.renameHandeler) {
        self.renameHandeler(nTx);
    }
    
    
    
    [self.window close];
    
}

#pragma mark window delegate
-(void)windowWillClose:(NSNotification *)notification {
    
    [NSApp stopModal];
    if ([[HCoreConfig shareConfig].holdWindoControllerArr containsObject:self]) {
            [[HCoreConfig shareConfig].holdWindoControllerArr removeObject:self];
    }

    
}



-(void)dealloc {



}
@end
